package com.cloudsigns.factorymanager2.project.presenter;

import com.cloudsigns.factorymanager2.project.bean.SurVeyOrderBean;
import com.cloudsigns.factorymanager2.project.iview.ISurveyOrderDetailView;
import com.cloudsigns.factorymanager2.project.model.ISurveyOrderDetailModel;
import com.cloudsigns.factorymanager2.project.model.SurveyOrderDetailModel;

/**
 * Created by tony on 2018/8/5.
 */

public class SurveyOrderDetailPresenter {
    private ISurveyOrderDetailView view;
    private ISurveyOrderDetailModel model;
    private android.os.Handler mHandler = new android.os.Handler();

    public SurveyOrderDetailPresenter(ISurveyOrderDetailView view) {
        this.view = view;
        this.model = new SurveyOrderDetailModel();
    }

    public void surveyOrderDetail() {

        model.getSurveyOrderDetail(view.getFeedbackDate(), view.getItemId(), view.getOrderId(),
                new  SurveyOrderDetailModel.OnSurveyOrderDetailListener() {
                    @Override
                    public void surveyOrderDetailSuccessed(final SurVeyOrderBean surVeyOrderBean) {
                        //需要在UI线程执行
                        mHandler.post(new Runnable() {
                            @Override
                            public void run() {
                                view.surveyOrderDetailSuccessed(surVeyOrderBean);
                                view.hideLoading();
                            }
                        });
                    }

                    @Override
                    public void surveyOrderDetailFailed(final String desc) {
                        //需要在UI线程执行
                        mHandler.post(new Runnable() {
                            @Override
                            public void run() {
                                view.surveyOrderDetailFailed(desc);
                                view.hideLoading();
                            }
                        });
                    }
                });
    }
}
